package com.wangxin.study8.day;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * @ClassName LocalDateMain
 * @Description LocalDate 表示了一个确切的日期，
 * 比如 2014-03-11。
 * 该对象值是不可变的，用起来和LocalTime基本一致。
 * 下面的例子展示了如何给Date对象加减天/月/年。另外要注意的是这些对象是不可变的，操作返回的总是一个新实例
 * @Author jojo.wang
 * @Date 2019-04-25 17:04
 * @Version 1.0
 **/
public class LocalDateMain {
    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        System.out.println("今天日期："+localDate);

        LocalDate tomorrow = localDate.plus(1, ChronoUnit.DAYS);
        System.out.println("明天日期："+tomorrow);

        LocalDate yesterday = localDate.minusDays(1);
        System.out.println("昨天的日期: "+yesterday);

        DayOfWeek dayOfWeek = localDate.getDayOfWeek();
        System.out.println("今天是周："+dayOfWeek);

        /**
         * 格式化
         */
        String str = "2019==04==25 01时06分09秒";
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy==MM==dd HH时mm分ss秒");
        LocalDateTime lt1 = LocalDateTime.parse(str,dateTimeFormatter);
        System.out.println(lt1);

        String str2 = "2014$$$四月$$$13 20小时";
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy$$$MMM$$$dd HH小时");
        LocalDateTime lt2 = LocalDateTime.parse(str2,dateTimeFormatter1);
        System.out.println(lt2);

        LocalDateTime rightNow = LocalDateTime.now();
        String date = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(rightNow);
        System.out.println(date);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss");
        System.out.println(formatter.format(rightNow));
    }
}
